package sapling.aop;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import sapling.dao.LogDao;
import sapling.model.Log;
import sapling.service.LogService;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

@Aspect
@Component
public class WebLogAspect {

    @Pointcut("execution(public * sapling.web.admin.LoginAction.login(..))")
    public void webLog() {
    }

    @Autowired
    private LogService logService;

    @Before("webLog()")
    public void doBefore(JoinPoint joinPoint) {
       ;
    }


    @AfterReturning("webLog()")
    public void doAfterReturning(JoinPoint joinPoint) {
        logService.saveLog(Log.TYPE_USER_LOGIN);
    }
}